{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 数学模型\n",
    "\n",
    "5本书借給3个人, 每人每次一本, 共有 $C_5^3$ 种"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. 代码实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 1), (0, 2, 3), \n",
      "(0, 2, 4), (0, 3, 1), (0, 3, 2), (0, 3, 4), (0, 4, 1), \n",
      "(0, 4, 2), (0, 4, 3), (1, 0, 2), (1, 0, 3), (1, 0, 4), \n",
      "(1, 2, 0), (1, 2, 3), (1, 2, 4), (1, 3, 0), (1, 3, 2), \n",
      "(1, 3, 4), (1, 4, 0), (1, 4, 2), (1, 4, 3), (2, 0, 1), \n",
      "(2, 0, 3), (2, 0, 4), (2, 1, 0), (2, 1, 3), (2, 1, 4), \n",
      "(2, 3, 0), (2, 3, 1), (2, 3, 4), (2, 4, 0), (2, 4, 1), \n",
      "(2, 4, 3), (3, 0, 1), (3, 0, 2), (3, 0, 4), (3, 1, 0), \n",
      "(3, 1, 2), (3, 1, 4), (3, 2, 0), (3, 2, 1), (3, 2, 4), \n",
      "(3, 4, 0), (3, 4, 1), (3, 4, 2), (4, 0, 1), (4, 0, 2), \n",
      "(4, 0, 3), (4, 1, 0), (4, 1, 2), (4, 1, 3), (4, 2, 0), \n",
      "(4, 2, 1), (4, 2, 3), (4, 3, 0), (4, 3, 1), (4, 3, 2), \n",
      "共 60 項\n"
     ]
    }
   ],
   "source": [
    "def 枚举():\n",
    "    书集 = [书 for 书 in range(5)]\n",
    "    for A in 书集:\n",
    "        for B in 书集:\n",
    "            if B == A:\n",
    "                continue\n",
    "            for C in 书集:\n",
    "                if C == B:\n",
    "                    continue\n",
    "                if C == A:\n",
    "                    continue\n",
    "                yield(A, B, C)\n",
    "\n",
    "计数 = 0\n",
    "for 项目 in 枚举():\n",
    "    if 计数 % 5 == 0:\n",
    "        print('\\r')\n",
    "    计数 += 1\n",
    "    print(项目, end=', ')\n",
    "\n",
    "print(f'\\n共 {计数} 項')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
